﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using WeifenLuo.WinFormsUI.Base;

namespace HRM
{
    public partial class MainForm : MainBaseForm
    {
        public FormMainMenu m_FunctionsMenu = new FormMainMenu();
        public FormOutputWindow m_outputWindow = new FormOutputWindow();
        public FormTaskList m_taskList = new FormTaskList();

        public MainForm()
        {
            InitializeComponent();

            #region More Administrator menu
            mnu_User.Click += new EventHandler(this.ToolStripMenuItem_Click);
            mnu_GroupUser.Click += new EventHandler(this.ToolStripMenuItem_Click);
            mnu_AccRight.Click += new EventHandler(this.ToolStripMenuItem_Click);

            ToolStripMenuItem item = new ToolStripMenuItem("&Parameters");
            ToolStripMenuItem itemSub;
            ToolStripSeparator itemSeparator = new ToolStripSeparator();
            
            mnu_Admin.DropDownItems.Insert(4, itemSeparator);
            item.Name = "mnu_Parameters";
            item.Click += new EventHandler(this.ToolStripMenuItem_Click);
            mnu_Admin.DropDownItems.Insert(5, item);
            item = new ToolStripMenuItem("GL &Account Group");
            item.Name = "mnu_GLAccGroup";
            item.Click += new EventHandler(this.ToolStripMenuItem_Click);
            mnu_Admin.DropDownItems.Insert(6, item);
            #endregion

            #region Data Center menu
            item = new ToolStripMenuItem("&Data Center");
            item.Name = "mnu_DataCenter";

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            ///////////// Company child menu //////////
            itemSub = new ToolStripMenuItem("Company");
            itemSub.Name = "mnu_Company";

            itemSeparator = new ToolStripSeparator();
            itemSub.DropDownItems.Add(itemSeparator);

            ToolStripMenuItem itemChild = new ToolStripMenuItem("Company Information");
            itemChild.Name = "mnu_CompInfo";
            itemChild.Click += new EventHandler(ToolStripMenuItem_Click);
            itemSub.DropDownItems.Add(itemChild);

            itemChild = new ToolStripMenuItem("Department");
            itemChild.Name = "mnu_Department";
            itemChild.Click += new EventHandler(ToolStripMenuItem_Click);
            itemSub.DropDownItems.Add(itemChild);

            itemChild = new ToolStripMenuItem("Position");
            itemChild.Name = "mnu_Position";
            itemChild.Click += new EventHandler(ToolStripMenuItem_Click);
            itemSub.DropDownItems.Add(itemChild);

            itemSeparator = new ToolStripSeparator();
            itemSub.DropDownItems.Add(itemSeparator);

            item.DropDownItems.Add(itemSub);
            ////////////////////////////////////////////////////////////

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Country/ Area");
            itemSub.Name = "mnu_CountryArea";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSub = new ToolStripMenuItem("Banking");
            itemSub.Name = "mnu_Banking";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSub = new ToolStripMenuItem("Contract Type");
            itemSub.Name = "mnu_ContractType";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Leave Type");
            itemSub.Name = "mnu_LeaveType";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSub = new ToolStripMenuItem("Overtime Type");
            itemSub.Name = "mnu_OvertimeType";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Literacy");
            itemSub.Name = "mnu_Literacy";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Race/ Dialect");
            itemSub.Name = "mnu_RaceDialect";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Place Of Registed HI. Type");
            itemSub.Name = "mnu_PORHIType";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSub = new ToolStripMenuItem("Place Of Registed HI.");
            itemSub.Name = "mnu_PORHI";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            mainMenu.Items.Insert(3, item);
            #endregion

            #region Human Resource menu
            item = new ToolStripMenuItem("&Human Resource");
            item.Name = "mnu_Personnel";

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Personal Profile");
            itemSub.Name = "mnu_PerProfile";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Search Personal Profile");
            itemSub.Name = "mnu_SerachProfile";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Training");
            itemSub.Name = "mnu_Training";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Health Check");
            itemSub.Name = "mnu_HealthChk";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);
            
            itemSub = new ToolStripMenuItem("Security Situation");
            itemSub.Name = "mnu_SecSituation";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Business Trip");
            itemSub.Name = "mnu_BeTrip";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Dependents Management");
            itemSub.Name = "mnu_Dependents";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSub = new ToolStripMenuItem("SI. HI. PIT Code");
            itemSub.Name = "mnu_SIHIPITCode";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            mainMenu.Items.Insert(4,item);
            #endregion

            #region Time Attendance menu
            item = new ToolStripMenuItem("&Time Attendance");
            item.Name = "mnu_TimeAtt";

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Define Shift");
            itemSub.Name = "mnu_DefineShift";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Shift Assign");
            itemSub.Name = "mnu_ShiftAssign";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Weekend Setup");
            itemSub.Name = "mnu_WkendSetup";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Holiday Setup");
            itemSub.Name = "mnu_HolidaySetup";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Leave Registration");
            itemSub.Name = "mnu_LeaveRegist";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            
            itemSub = new ToolStripMenuItem("Overtime Registration");
            itemSub.Name = "mnu_OvertimeRegist";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSub = new ToolStripMenuItem("Overtime Adjustment");
            itemSub.Name = "mnu_OTAdj";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Machine Time Sheet");
            itemSub.Name = "mnu_MachineTimeSheet";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSub = new ToolStripMenuItem("Manual Time Sheet");
            itemSub.Name = "mnu_ManualTimeSheet";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSub = new ToolStripMenuItem("Working Time Adjustment");
            itemSub.Name = "mnu_WrkTimeAdj";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
           

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Allowance Fee");
            itemSub.Name = "mnu_Allowance";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Bonus Fee");
            itemSub.Name = "mnu_Bonus";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Maternity Management");
            itemSub.Name = "mnu_Maternity";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);
            
            mainMenu.Items.Insert(5, item);
            #endregion

            #region Payroll menu
            item = new ToolStripMenuItem("&Payroll");
            item.Name = "mnu_Payroll";

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Tax Reference");
            itemSub.Name = "mnu_TaxRef";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Curency");
            itemSub.Name = "mnu_Curency";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Salary Advance");
            itemSub.Name = "mnu_SalAdvance";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Calculate Salary");
            itemSub.Name = "mnu_CalculateSal";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("View Salary");
            itemSub.Name = "mnu_ViewSal";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Pay Slip");
            itemSub.Name = "mnu_PaySlip";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Close Payroll");
            itemSub.Name = "mnu_ClosePayroll";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            mainMenu.Items.Insert(6, item);
            #endregion

            #region Insurance menu
            item = new ToolStripMenuItem("&Insurance");
            item.Name = "mnu_Insurance";

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("SI. Applying Employee");
            itemSub.Name = "mnu_SIApplying";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("SI. Additional Payment");
            itemSub.Name = "mnu_SIAddPayment";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("SI., HI.Profile Adjustment");
            itemSub.Name = "mnu_SIHIProfileAdj";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            mainMenu.Items.Insert(7, item);
            #endregion

            #region Reports menu
            item = new ToolStripMenuItem("&Reports");
            item.Name = "mnu_Rpts";

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            itemSub = new ToolStripMenuItem("Personnel");
            itemSub.Name = "mnu_RptsPersonnel";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Time Attendance");
            itemSub.Name = "mnu_RptsTimeAtt";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);  
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Payroll");
            itemSub.Name = "mnu_RptsPayroll";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);
            itemSub = new ToolStripMenuItem("Insurance");
            itemSub.Name = "mnu_RptsInsurance";
            itemSub.Click += new EventHandler(ToolStripMenuItem_Click);
            item.DropDownItems.Add(itemSub);

            itemSeparator = new ToolStripSeparator();
            item.DropDownItems.Add(itemSeparator);

            mainMenu.Items.Insert(8, item);
            #endregion

            mnu_About.Click += new EventHandler(ToolStripMenuItem_Click);

            EnableMainmenuFunction(false);

            ///////////////////////////////////////////////////////////////////
            m_FunctionsMenu = new FormMainMenu();
            m_FunctionsMenu.RightToLeftLayout = RightToLeftLayout;
            m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
        }

        protected override void MainBaseForm_Load(object sender, EventArgs e)
        {
            base.MainBaseForm_Load(sender, e);
        }

        protected override void EnableMainmenuFunction(bool ab_switch)
        {
            mnu_Admin.DropDownItems["mnu_GLAccGroup"].Visible = ab_switch; // mnu_GLAccGroup
            mnu_Admin.DropDownItems["mnu_Parameters"].Visible = ab_switch; // mnu_Parameters
            mnu_Admin.DropDownItems[4].Visible = ab_switch; // menu Separator

            mainMenu.Items["mnu_DataCenter"].Visible = ab_switch;
            mainMenu.Items["mnu_Personnel"].Visible = ab_switch;
            mainMenu.Items["mnu_TimeAtt"].Visible = ab_switch;
            mainMenu.Items["mnu_Payroll"].Visible = ab_switch;
            mainMenu.Items["mnu_Insurance"].Visible = ab_switch;
            mainMenu.Items["mnu_Rpts"].Visible = ab_switch;
        }

        #region Help menu function
        private void AboutClick()
        {
            AboutDialog aboutDlg = new AboutDialog();
            aboutDlg.ShowDialog();
        }
        #endregion

        protected override void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            base.ToolStripMenuItem_Click(sender, e);
            if (mbClicked) return;

            switch (((ToolStripMenuItem)sender).Name)
            {
                #region Admin menu
                case "mnu_User":
                    this.ShowForm(new FormUserInfo());
                    break;

                case "mnu_GroupUser":
                    this.ShowForm(new FormGroupInfo());
                    break;

                case "mnu_AccRight":
                    this.ShowForm(new FormProcedureSecurity());
                    break;

                case "mnu_Parameters":
                    this.ShowForm(new FormParameters());
                    break;

                case "mnu_GLAccGroup":
                    this.ShowForm(new FormGLAccGroup());
                    break;
                #endregion

                #region Data Center menu
                case "mnu_CompInfo":
                    this.ShowForm(new FormCompanyInfo());
                    break;

                case "mnu_Department":
                    this.ShowForm(new FormDepartment());
                    break;

                case "mnu_Position":
                    this.ShowForm(new FormPosition());
                    break;

                case "mnu_CountryArea":
                    this.ShowForm(new FormCountry());
                    break;

                case "mnu_Banking":
                    this.ShowForm(new FormBankInfo());
                    break;

                case "mnu_ContractType":
                    this.ShowForm(new FormContractType());
                    break;

                case "mnu_LeaveType":
                    this.ShowForm(new FormLeaveType());
                    break;

                case "mnu_OvertimeType":
                    this.ShowForm(new FormOvertimeType());
                    break;

                case "mnu_Literacy":
                    this.ShowForm(new FormLiteracy());
                    break;

                case "mnu_RaceDialect":
                    this.ShowForm(new FormRaceDialect());
                    break;

                case "mnu_PORHIType":
                    this.ShowForm(new FormPlaceOfRegHIType());
                    break;

                case "mnu_PORHI":
                    this.ShowForm(new FormPlaceOfRegistedHI());
                    break;

                #endregion

                #region Human Resource menu
                case "mnu_PerProfile":
                    this.ShowForm(new FormPersonalProfile());
                    break;

                case "mnu_SerachProfile":
                    break;

                case "mnu_Training":
                    this.ShowForm(new FormTraining());
                    break;

                case "mnu_HealthChk":
                    this.ShowForm(new FormHealthCheck());
                    break;

                case "mnu_SecSituation":
                    break;

                case "mnu_BeTrip":
                    this.ShowForm(new FormBusinessTrip());
                    break;

                case "mnu_Dependents":
                    this.ShowForm(new FormDependent());
                    break;

                case "mnu_SIHIPITCode":
                    this.ShowForm(new FormHISIPIT_Info());
                    break;
                #endregion
                #region Time Attendance
                case "mnu_DefineShift":
                    this.ShowForm(new FormDefineShift());
                    break;
                case "mnu_ShiftAssign":
                    this.ShowForm(new FormAssignShift());
                    break;
                case "mnu_WkendSetup":
                    this.ShowForm(new FormWeekendSetup());
                    break;
                case "mnu_HolidaySetup":
                    this.ShowForm(new FormHolidaySetup());
                    break;
                case "mnu_LeaveRegist":
                    this.ShowForm(new FormLeaveRegistration());
                    break;
                case "mnu_OvertimeRegist":
                    this.ShowForm(new FormOvertimeRegistration());
                    break;
                case "mnu_ManualTimeSheet":
                    this.ShowForm(new FormManualTimeSheet());
                    break;

                case "mnu_MachineTimeSheet":
                    this.ShowForm(new FormMachineTimeSheet());
                    break;
                case "mnu_WrkTimeAdj":
                    this.ShowForm(new FormWorkingTimeAdjustment());
                    break;
                case "mnu_OTAdj":
                    this.ShowForm(new FormOvertimeAdjustment());
                    break;
                case "mnu_Allowance":
                    this.ShowForm(new FormAllowanceFee());
                    break;
                case "mnu_Bonus":
                    this.ShowForm(new FormBonusFee());
                    break;
                case "mnu_Maternity":
                    this.ShowForm(new FormMaternity());
                    break;
                #endregion
                #region Payroll menu
                case "mnu_TaxRef":
                    this.ShowForm(new FormTaxReference());
                    break;
                case "mnu_Curency":
                    break;
                case "mnu_SalAdvance":
                    this.ShowForm(new FormSalaryAdvance());
                    break;
                case "mnu_CalculateSal":
                    FormCalculatePayroll dlgCalculatePayroll = new FormCalculatePayroll();
                    dlgCalculatePayroll.mMainForm = this;
                    dlgCalculatePayroll.ShowDialog();
                    break;
                case "mnu_ViewSal":
                    this.ShowForm(new FormViewSalary());
                    break;
                case "mnu_PaySlip":
                    break;
                case "mnu_ClosePayroll":
                    this.ShowForm(new FormSalaryPeriod());
                    break;
                #endregion
                #region Insurance menu
                case "mnu_SIApplying":
                    this.ShowForm(new FormSIApplying());
                    break;
                case "mnu_SIAddPayment":
                    this.ShowForm(new FormSIAdditionalPayment());
                    break;
                case "mnu_SIHIProfileAdj":
                    this.ShowForm(new FormSIHIProfileAdjustment());
                    break;
                #endregion
                #region Report menu
                case "mnu_RptsPersonnel":
                    break;
                case "mnu_RptsTimeAtt":
                    break;
                case "mnu_RptsPayroll":
                    break;
                case "mnu_RptsInsurance":
                    break;
                #endregion

                case "mnu_About":
                    AboutClick();
                    break;
            }
        }

        #region Functions
        private IDockContent GetContentFromPersistString(string persistString)
        {
            if (persistString == typeof(FormMainMenu).ToString())
                return m_FunctionsMenu;
            else if (persistString == typeof(FormOutputWindow).ToString())
                return m_outputWindow;
            else if (persistString == typeof(FormTaskList).ToString())
                return m_taskList;
            else
            {
                string[] parsedStrings = persistString.Split(new char[] { ',' });
                if (parsedStrings.Length != 3)
                    return null;

                if (parsedStrings[0] != typeof(FormBase).ToString())
                    return null;

                FormBase dummyDoc = new FormBase();
                if (parsedStrings[1] != string.Empty)
                    dummyDoc.FileName = parsedStrings[1];
                if (parsedStrings[2] != string.Empty)
                    dummyDoc.Text = parsedStrings[2];

                return dummyDoc;
            }
        }
        #endregion

    }
}
